package com.leizi.igym.controller.user;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leizi.igym.constant.EquipConstant;
import com.leizi.igym.dto.EquipAddDTO;
import com.leizi.igym.dto.EquipDTO;
import com.leizi.igym.dto.EquipPageQueryDTO;
import com.leizi.igym.enums.ReturnCodeEnum;
import com.leizi.igym.exception.BusinessException;
import com.leizi.igym.resp.PageResult;
import com.leizi.igym.resp.Result;
import com.leizi.igym.service.EquipService;
import com.leizi.igym.service.TrainerService;
import com.leizi.igym.utils.ThrowUtils;
import com.leizi.igym.vo.EquipVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @Author: leizi0110
 * @CreateTime: 2024-04-09  10:06
 * @Description:
 */

@RestController("userEquipController")
@RequestMapping("/user/equip")
@Tag(name = "用户端-器械相关接口")
@Slf4j
public class EquipController {

    @Resource
    private EquipService equipService;

    @Operation(summary = "用户端：查询器械所有信息")
    @GetMapping
    public Result getAll() {
        log.info("用户端正在查询所有器械信息");
        List<EquipVO> equipVOList = equipService.getAllWithPart();
        return Result.ok(equipVOList);
    }

    @Operation(summary = "用户端：根据id查询器械信息")
    @GetMapping("{id}")
    public Result<EquipVO> getById(@PathVariable("id") Long id) {
        log.info("用户端正在根据id查询器械信息，id为：{}", id);
        ThrowUtils.throwIf(Objects.isNull(id) || id <= 0,
                ReturnCodeEnum.PARAMS_ERROR);

        EquipVO equipVO = equipService.getByIdWithPart(id);
        if (Objects.isNull(equipVO)) {
            throw new BusinessException(ReturnCodeEnum.NOT_FOUND_ERROR, "该器械信息不存在！");
        }
        return Result.ok(equipVO);
    }
}
